<h1><?php echo $this->translate('menu');?></h1>

<table class="admin-table">
    <thead>
    <tr>
        <th><?php echo $this->translate('title');?></th>
        <th><?php echo $this->translate('route');?></th>
        <th><?php echo $this->translate('reorder');?></th>
        <th><?php echo $this->translate('action');?></th>
    </tr>
    </thead>
    <tbody>
    <?php
    $prevLevelItem = array();

    foreach ($this->tree as $k => $item) {
        $this->tree[$k]['hasNextSibling'] = false;
        $this->tree[$k]['hasPrevSibling'] = false;

        if(false === empty($prevLevelItem[$item['level']])) {
            $prevItem = $prevLevelItem[$item['level']];

            if($this->tree[$prevItem]['rgt'] == ($item['lft']-1) ) {
                $this->tree[$k]['hasPrevSibling'] = true;
                $this->tree[$prevItem]['hasNextSibling'] = true;
            }
        }

        $prevLevelItem[$item['level']] = $k;
    }


    foreach ($this->tree as $item):
        if(false === empty($item['sysmap_identifier'])) {
            if(false === $this->acl->isAllowed(NULL,$item['sysmap_identifier'])) {
                continue;
            }
        }
        ?>
    <tr>
        <td><?php
            echo str_repeat('&nbsp;&nbsp;&nbsp;', $item['level']);
            echo '<sup>|</sup>-&nbsp;'.$item['title'];?></td>
        <td><?php echo $item['route'];?></td>
        <td><?php
            if($item['type'] != Navigation_Model_Navigation::TYPE_NAVIGATION_ROOT ) {
                $showLine = false;

                if($item['hasNextSibling']) {
                    echo $this->link( 'down' ,$this->url(array('module'=>'navigation','action'=>'move','id'=>$item['id'],'dir'=>'down'),'admin',true) );
                    $showLine = true;
                }

                if($item['hasPrevSibling']) {
                    if($showLine) echo " | ";
                    echo $this->link( 'up'   ,$this->url(array('module'=>'navigation','action'=>'move','id'=>$item['id'],'dir'=>'up'  ),'admin',true) );
                }
            }
            ?>
        </td>
        <td align="center" nowrap="nowrap">
		<?php

		if ($item['read_only'] == false || $item['type'] != Navigation_Model_Navigation::TYPE_NAVIGATION_ROOT):
			echo $this->link(
				'edit',
				$this->url(array('action' => 'edit-menu-item', 'module' => 'navigation', 'id' => $item['id'])),
				array('class' => 'edit-item')
			);
		?>

		&nbsp;

		<?php
			echo $this->link(
				'delete',
				$this->url(array('action' => 'delete-menu-item', 'module' => 'navigation', 'id' => $item['id'])),
				array('class' => 'delete-item')
			);

		endif;
		?>
	</td>
    </tr>
    <?php endforeach; ?>
    </tbody>
</table>